package com.guobox.movies.view.mview;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.AttributeSet;

/**
 * Created by xxl on 16/7/11.
 */
public class RoundTextView extends android.support.v7.widget.AppCompatTextView {
    Paint bgPaint;
    int left,top,right,bottom;
    int textColor;
    public RoundTextView(Context context) {
        super(context);
        bgPaint = new Paint();
        textColor = this.getCurrentTextColor();
    }

    public RoundTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
        bgPaint = new Paint();
        textColor = this.getCurrentTextColor();
    }

    public RoundTextView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        bgPaint = new Paint();
        textColor = this.getCurrentTextColor();
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }

    @Override
    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
        super.onLayout(changed, left, top, right, bottom);
        this.left = left;
        this.top = top;
        this.right = right;
        this.bottom = bottom;
    }

    @Override
    public boolean onPreDraw() {

        return super.onPreDraw();
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);

        bgPaint.setAntiAlias(true);
        bgPaint.setStyle(Paint.Style.STROKE);
        bgPaint.setColor(getCurrentTextColor());
        bgPaint.setStrokeWidth(1);
        canvas.drawRoundRect(1,2,right-left-1,bottom-top-1,5,5,bgPaint);
    }
}
